package com.wutongyu.mannyburger;

import android.app.Dialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class ImageSliderAdapter extends RecyclerView.Adapter<ImageSliderAdapter.ImageViewHolder> {

    private List<Integer> imageList;

    public ImageSliderAdapter(List<Integer> imageList) {
        this.imageList = imageList;
    }

    @NonNull
    @Override
    public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.product_image_slider_item, parent, false);
        return new ImageViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
        holder.imageView.setImageResource(imageList.get(position));
        
        // 添加点击事件，点击图片可放大查看
        holder.imageView.setOnClickListener(v -> {
            showFullScreenImage(v, imageList.get(position));
        });
    }

    @Override
    public int getItemCount() {
        return imageList.size();
    }
    
    // 显示全屏图片的方法
    private void showFullScreenImage(View view, int imageResource) {
        Dialog dialog = new Dialog(view.getContext(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.dialog_fullscreen_image);
        
        ImageView fullscreenImageView = dialog.findViewById(R.id.fullscreen_image);
        fullscreenImageView.setImageResource(imageResource);
        
        // 点击图片关闭对话框
        fullscreenImageView.setOnClickListener(v -> dialog.dismiss());
        
        dialog.show();
    }

    static class ImageViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;

        public ImageViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.product_image);
        }
    }
} 